package com.xk._03真题骗._00bean;

import com.xk._01基础篇._06二叉搜索树.printer.BinaryTreeInfo;
import com.xk._01基础篇._06二叉搜索树.printer.BinaryTrees;

/**
 * @description:
 * @author: xu
 * @date: 2022/10/30 22:47
 */
public class TreeNode implements BinaryTreeInfo {
    public int val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode() {}
    public TreeNode(int val) {
        this.val = val;
    }
    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    @Override
    public Object root() {
        return this;
    }

    @Override
    public Object left(Object node) {
        return ((TreeNode) node).left;
    }

    @Override
    public Object right(Object node) {
        return ((TreeNode) node).right;
    }

    @Override
    public Object string(Object node) {
        return ((TreeNode) node).val + "";
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(6);
        TreeNode node1 = new TreeNode(3);
        TreeNode node2 = new TreeNode(2);
        TreeNode node3 = new TreeNode(1);
        TreeNode node4 = new TreeNode(5);
        TreeNode node5 = new TreeNode(0);

        root.left = node1;
        root.right = node4;
        node1.right = node2;
        node2.right = node3;
        node4.left = node5;

        BinaryTrees.println(root);
    }
}
